//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<StyleText.h>
///	@path	~/src/gui/style/
///	@date	2008/10/21
///	@brief	.

#pragma once

#include "xeres.h"

#include "lib/utilities/string.h"
#include "lib/math/pair.h"

#include "gui/style/style.h"
#include "gui/composite/composition.h"

namespace xeres {

	/*! 
		\class	StyleText
		\brief	Encapsulates a text representation.
	*/
	class StyleText
	{
	public:

		/// \ctor
		StyleText( void );

		/// \ctor
		StyleText( const WString& text );

		/// \dtor
		~StyleText( void );

		/// \name	Local Methods
		//@{

		/// \brief	Get style.
		RefWeak<CTextStyle> GetStyle( void ) { return m_style; }

		/// \brief	Set style.
		void SetStyle( Ref<CTextStyle> style );

		/// \brief	Get string.
		const WString& GetString( void ) const { return m_buffer; }

		/// \brief	Set string.
		void SetString( const WString& str );

		/// \brief	Draw text to composition.
		void DrawText( Composition& composition , const Rect<int>& place , const Rect<int>& bound , int offset = 0 , int len = -1 );

		//@}

	private:

		/// \brief	Re-layout text.
		void RelayoutText( void );

		//@ data
		WString				m_buffer;
		Ref<CTextStyle>		m_style;
		int *				m_arrangement;
		int					m_count;
		int					m_width;
	};

	/*! 
		\class	StyleTextBlock
		\brief
	*/
	class StyleTextBlock
	{
	public:

		/// \ctor
		StyleTextBlock( void );

		/// \ctor
		StyleTextBlock( const WString& text );

		/// \dtor
		virtual ~StyleTextBlock( void );

		/// \name	Local Methods
		//@{

		/// \brief	Get style.
		RefWeak<CTextStyle> GetStyle( void ) { return m_style; }

		/// \brief	Set style.
		void SetStyle( Ref<CTextStyle> style );

		/// \brief	Get string.
		const WString& GetString( void ) const { return m_buffer; }

		/// \brief	Set string.
		void SetString( const WString& str );

		/// \brief	Set size.
		void SetSize( const Pair<int>& size );

		/// \brief	Get line.

		/// \brief	Draw text to composition.
		void DrawText( Composition& composition , const Rect<int>& place , const Rect<int>& bound , int offset = 0 , int len = -1 );

		//@}

	private:

		/// \brief	Clear lines.
		void ClearLines( void );

		/// \brief	Re-layout text.
		void RelayoutText( void );

		struct _Line
		{
			int *		arrangement;
			int			startIndex;
			int			count;
			int			width;
			int			start_y;
		};

		//@ data
		WString				m_buffer;
		Ref<CTextStyle>		m_style;
		Pair<int>			m_size;
		std::vector<_Line>	m_lines;
		int *				m_arrangement;
		int					m_count;
		int					m_height;
		int					m_width;
	};

} // namespace xeres
